
#include <stdio.h>

#include <time.h>

#include <string.h>

static void tm_show(const struct tm *t)
{
    printf("date(%d:%d:%d)\n"
           "time(%d:%d:%d)\n"
           "gmtoff(%ld)\n"
           "isdst(%d)\n"
           "wday(%d)\n"
           "yday(%d)\n"
           "zone(%s)\n",
           t->tm_year+1900, t->tm_mon+1, t->tm_mday,
           t->tm_hour, t->tm_min, t->tm_sec,
           t->tm_gmtoff,
           t->tm_isdst,
           t->tm_wday, t->tm_yday, t->tm_zone);
}

int main(int argc, char *argv[])
{
    time_t t = time(NULL);
    struct tm *tm1 = localtime(&t);
    struct tm *tm2 = gmtime(&t);
    struct tm tm3;
    char *str1 = ctime(&t);
    char *str2 = asctime(tm1);
    char str3[64] = {0};
    time_t t2 = mktime(tm1);

    strftime(str3, 64, "%Y/%m/%d", tm1);

    printf("time_t  : (%ld)\n"
           "mktime  : (%ld)\n"
           "ctime   : %s"
           "asctime : %s"
           "strftime: (%s)\n", t, t2, str1, str2, str3);

    printf("----- localtime -----\n");
    tm_show(tm1);
    printf("----- gmtime -----\n");
    tm_show(tm2);

    memset(&tm3, 0, sizeof(tm3));
    tm3.tm_year = tm1->tm_year;
    tm3.tm_mon = tm1->tm_mon;
    tm3.tm_mday = tm1->tm_mday;
//    tm3.tm_hour = tm1->tm_hour;
    tm3.tm_hour = 0;
    tm3.tm_min = tm1->tm_min;
    tm3.tm_sec = tm1->tm_sec;

    time_t i = mktime(&tm3);
    printf("mktime  : (%ld)\n", mktime(&tm3));
    printf("ctime   : %s", ctime(&i));

    return 0;
}
